#ifndef VIDEOTOOL_H
#define VIDEOTOOL_H
#include <QAbstractVideoSurface>
#include <QPainter>
#include <QPaintEvent>
#include <QWidget>

class myvideosurface : public QAbstractVideoSurface
{
    Q_OBJECT

public:
    explicit myvideosurface(QObject *parent = nullptr);
    ~myvideosurface() Q_DECL_OVERRIDE;
    bool present(const QVideoFrame &) Q_DECL_OVERRIDE;  // 每一帧画面将回到这里处理
    bool start(const QVideoSurfaceFormat &) Q_DECL_OVERRIDE;    // 摄像头开启状态就会调用
    void stop() Q_DECL_OVERRIDE;    //出错就停止了
    bool isFormatSupported(const QVideoSurfaceFormat &) const Q_DECL_OVERRIDE;    //将视频流中像素格式转换成格式对等的图片格式，若无对等的格式，返回QImage::Format_Invalid
    QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType type = QAbstractVideoBuffer::NoHandle) const Q_DECL_OVERRIDE;

private:
    QVideoFrame m_currentFrame; //视频帧

signals:
    void frameAvailable(QVideoFrame);   //将捕获的每一帧视频通过信号槽方式发出去
};

class opencamera : public QWidget
{
    Q_OBJECT

public:
    explicit opencamera(QWidget *parent = nullptr);

public slots:
    void showImage(QImage);                            //一但捕获到照片就显示

protected:
    void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;    //Q_DECL_OVERRIDE对负累的虚函数进行重载
public:
    QImage videoImg;
};
#endif // VIDEOTOOL_H
